<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>学生仪表盘</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f0fff0;
            margin: 0;
            padding: 0;
            display: flex;
            flex-direction: column;
            align-items: center;
            min-height: 100vh;
            background-size: cover;
        }
        .container {
            background-color: rgba(255, 255, 255, 0.95);
            padding: 30px;
            border-radius: 10px;
            text-align: center;
            margin-top: 30px;
            width: 90%;
            max-width: 600px;
            box-shadow: 0 0 20px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
        }
        h2 {
            color: #555;
            margin-top: 20px;
        }
        ul {
            list-style-type: none;
            padding: 0;
        }
        li {
            background-color: #e6ffe6;
            margin: 5px 0;
            padding: 10px;
            border-radius: 5px;
            text-align: left;
        }
        button {
            padding: 10px 20px;
            background-color: #dc3545;
            color: white;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            margin-top: 20px;
        }
        button:hover {
            background-color: #c82333;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>学生仪表盘</h1>
        <h2>已签到记录</h2>
        <ul id="records-list">
            <!-- 签到记录将通过JavaScript填充 -->
        </ul>
        <button id="logout-button">登出</button>
    </div>

    <script>
        // 获取签到记录
        function getRecords() {
            fetch('/records')
            .then(response => response.json())
            .then(data => {
                var recordsList = document.getElementById('records-list');
                recordsList.innerHTML = '';
                if (data.records && data.records.length > 0) {
                    data.records.forEach(function(record) {
                        var listItem = document.createElement('li');
                        var signInTime = new Date(record.sign_in_time).toLocaleString();
                        listItem.textContent = '签到时间：' + signInTime;
                        recordsList.appendChild(listItem);
                    });
                } else {
                    recordsList.innerHTML = '<li>暂无签到记录</li>';
                }
            })
            .catch(error => {
                console.error('Error:', error);
                alert('获取签到记录失败：' + error);
            });
        }

        // 登出功能
        document.getElementById('logout-button').addEventListener('click', function() {
            window.location.href = '/logout';
        });

        // 页面加载时获取签到记录
        window.onload = function() {
            getRecords();
        };
    </script>
</body>
</html>